// src/router/index.js
import { createRouter, createWebHistory } from 'vue-router'
import HomeLayout from '../views/HomeLayout.vue' // B. 导航框架/首页

const router = createRouter({
  history: createWebHistory(import.meta.env.BASE_URL),
  routes: [
    // ----------------------------------------------------
    // 1. 独立布局路由 (A. 登录/注册页)
    // ----------------------------------------------------
    {
      path: '/user/login',
      name: 'Login',
      component: () => import('../views/user/LoginPage.vue'),
    },
    {
      // 路径与 SmartCreation.vue 中的 router.push 保持一致
      path: '/editor/:templateId/texture/:textureId',
      name: 'CreationEditor',
      // 请根据您的实际文件路径调整 import 路径
      component: () => import('../views/CreationEditor.vue'),
      props: true, // 允许将路由参数作为 props 传递
      meta: { requiresUser: true, fullScreen: true }, // 编辑器通常需要用户登录和全屏
    },

    // ----------------------------------------------------
    // 2. 主框架布局路由 (包含 B, C, D, E, F, G, H)
    // 所有这些页面都共享 HomeLayout 的 Header 和 Footer
    // ----------------------------------------------------
    {
      path: '/',
      name: 'HomeLayout',
      component: HomeLayout, // B. 导航框架/首页
      children: [
        // C. 模板浏览页 (默认子路由: /)
        {
          path: '',
          name: 'TemplateExplorer',
          component: () => import('../views/TemplateExplorer.vue'),
        },

        // D. 模板详情页 (/templates/:id)
        {
          path: 'templates/:id',
          name: 'TemplateDetail',
          component: () => import('../views/TemplateDetail.vue'),
          props: true, // 允许将路由参数 :id 作为组件的 prop 传递
        },

        // E. 智能创作页 (/create/:id?)
        {
          path: 'create/:id?', // :id 是可选参数
          name: 'SmartCreation',
          component: () => import('../views/SmartCreation.vue'),
          props: true,
          meta: { requiresUser: true }, // 只有登录用户才能访问 (待实现)
        },

        // F. 个人中心/作品集 (/profile)
        {
          path: 'profile',
          name: 'UserProfile',
          component: () => import('../views/UserProfile.vue'),
          meta: { requiresUser: true },
        },

        // G. 传承人/派系页 (/heritage)
        {
          path: 'heritage',
          name: 'HeritagePage',
          component: () => import('../views/HeritagePage.vue'),
        },

        // H. 作者详情页 (/author/:id)
        {
          path: 'author/:id',
          name: 'AuthorDetail',
          component: () => import('../views/AuthorDetail.vue'),
          props: true,
        },
      ],
    },

    // ----------------------------------------------------
    // 3. 404 Not Found 路由 (放置在所有路由的最后)
    // ----------------------------------------------------
    {
      path: '/:pathMatch(.*)*',
      name: 'NotFound',
      component: () => import('../views/NotFound.vue'),
    },
  ],
})

export default router
